package com.ficus.road.maintain.dao;

import com.ficus.road.maintain.core.dao.BaseMongoDao;
import com.ficus.road.maintain.core.model.GetRoadPCIAndPQIResponse;
import com.ficus.road.maintain.core.model.smartnew.SmartValuation;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.List;

/**
 * 弹窗，获取RQI/PCI
 * @author xiawen yang
 * @date 2023/8/10 下午9:26
 */
@Component
public class GetRoadPCIAndPQIDao extends BaseMongoDao<SmartValuation, String> {
    @Override
    public String getCollectionName() {
        return "smart_valuation_merged";
    }

    public List<GetRoadPCIAndPQIResponse> GetRoadPCIAndPQI(String roadName){
// 构建查询条件
        Criteria roadName1 = Criteria.where("roadName").is(roadName);
        Query query = new Query(roadName1);
        ArrayList<GetRoadPCIAndPQIResponse> list = new ArrayList<>();
        for (SmartValuation smartValuation : this.findByQuery(query)) {
            GetRoadPCIAndPQIResponse getRoadPCIAndPQIResponse = new GetRoadPCIAndPQIResponse();
            getRoadPCIAndPQIResponse.setRoadName(roadName);
            getRoadPCIAndPQIResponse.setRqi(smartValuation.getRQI());
            getRoadPCIAndPQIResponse.setPci(smartValuation.getPCI());
            list.add(getRoadPCIAndPQIResponse);
        }

        return list;
    }
}
